
const child_process = require('child_process');

let testArr = []; // 要打包的项目列表
let filterTest = [] // 要过滤的项目

const projects = require('./config/projectJson.json')

Object.keys(projects).forEach(proName => {
    if (!filterTest.includes(proName)) {
        testArr.push(proName);
    }
});

let testCurr = 0;
const testNum = testArr.length;

console.log('项目列表', testArr, '数目' + testArr.length)
workerProcess(0)

function workerProcess(index) {
    const _process = child_process.exec('yarn test ' + testArr[index]);
    console.log(`loading：正在打包${testArr[index]}`);
    _process.on('exit', function(code) {
        testCurr++
        if ((testNum - testCurr)) {
            console.log(`子进程${testArr[index]}已退出，退出码 ${code != 0 ? code + '，异常、异常' : '0,成功'}`);
            workerProcess(testCurr)
        } else {
            console.log(`子进程${testArr[index]}已退出，退出码 ${code != 0 ? code + '，异常、异常' : '0,成功'}`);
            console.log('打包完成')
        }
    });
}
